package com.technician.controller;

import cn.hutool.http.HttpUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
public class HelloController {

    @RequestMapping("/hello")
    @PreAuthorize("hasAuthority('system:user:list')")
    public String hello(HttpServletRequest request){
//        throw new GlobalSystemException(HttpStatusEnum.ERROR_RESPONSE);
        return "hello";
    }

    @RequestMapping("/wxLogin")
    public String wxLogin(String code){
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("appid", "wx14ae3b0dae7ef5ce");
        param.put("secret", "f4cbe620abd677b599cf0970192dd7cc");
        param.put("js_code", code);
        param.put("grant_type", "authorization_code");
        String post = HttpUtil.post("https://api.weixin.qq.com/sns/jscode2session", param);
        return post;
    }
}